package eu.news.interconnect.server;

import eu.news.config.Debugger;
import eu.news.interconnect.Entity;
import eu.news.interconnect.Message;
import eu.news.interconnect.NewsEntity;
import eu.news.interconnect.server.delegate.Query;
import eu.news.interconnect.server.delegate.UpdateNews;

/**
 * 服务端任务处理分配
 * 
 * @author WZZ
 * 
 */
public class ActionDispatch {

	public final static Class<? extends Delegater> UPDATE_NEWS = UpdateNews.class;

	public final static Class<? extends Delegater> QUERY = Query.class;
	
	public static Delegater getDelegater(Message message) {
		Entity entity = message.getEntity();
		try {
			switch (message.getType()) {
			case Message.TYPE.SEND_CONTENT:
				if (entity instanceof NewsEntity)
					return UPDATE_NEWS.newInstance();
			case Message.TYPE.QUERY:
				return QUERY.newInstance();
			}
		} catch (InstantiationException e) {
			Debugger.printStackTrace(e);
		} catch (IllegalAccessException e) {
			Debugger.printStackTrace(e);
		}
		return null;
	}
}
